#ifndef _BASE_STMT_H_
#define _BASE_STMT_H_

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mysql.h"
#include "Log4Cplus.h"


class BaseStmt
{	
	public:
		BaseStmt();
		~BaseStmt();

		/*
		0 , Success ;
		CR_COMMANDS_OUT_OF_SYNC 以不恰当的顺序执行了命令 ;
		CR_OUT_OF_MEMORY		内存溢出 ;
	 	CR_SERVER_GONE_ERROR	MySQL服务器不可用 ;
		CR_SERVER_LOST			查询过程中，与服务器的连接丢失 ;
		CR_UNKNOWN_ERROR		出现未知错误 ;
		*/
		
		int Prepare(const char *query, unsigned long length);

		int GetStmt(MYSQL_STMT* pStmt);
		
	
		// nParamPos , nParam, nType, columType, columSize*, nParamSize	
		
		//BindInParam 绑定输入参数
		int BindIn(int nParamPos, char *szParam, long unsigned int nParamLength);

		int BindIn(int nParamPos, short int *nParam, long unsigned int nParamLength);
		
		int BindIn(int nParamPos, int *nParam, long unsigned int nParamLength);
		
		int BindIn(int nParamPos, long long int *nParam, long unsigned int nParamLength);

		int BindIn(int nParamPos, float *fParam,  long unsigned int nParamLength);

		int BindIn(int nParamPos, double *dParam, long unsigned int nParamLength);

		int BindIn(int nParamPos, MYSQL_TIME *tParam, long unsigned int nParamLength);

		
 		//BindOutRes 绑定输出参数
		int BindOut(int nResPos, char *szRes,  long unsigned int nBufLength);

		int BindOut(int nResPos, short int *nParam, long unsigned int nBufLength);

		int BindOut(int nResPos, int *nParam, long unsigned int nBufLength);
		
		int BindOut(int nResPos, long long int *nParam, long unsigned int nBufLength);

		int BindOut(int nResPos, float *fParam,  long unsigned int nBufLength);

		int BindOut(int nResPos, double *dParam, long unsigned int nBufLength);

		int BindOut(int nResPos, MYSQL_TIME *tParam, long unsigned int nBufLength);
		
		int Excute();
			
		int Fetch();

	private:

		int m_nBindInParamCounts;			//统计绑定的输入参数个数		
		int m_nBindOutResultColumCounts;	//统计绑定的输出参数个数
		int m_nCheckParam;					//检验绑定输入的参数个数
		int m_nCheckResultColum;			//检验绑定输入的参数个数
		MYSQL_STMT	*m_pStmt;				//接数据库的链接
		MYSQL_RES   *m_pPrepare_meta_result;//取得结果集的参数
		MYSQL_BIND	*m_pBindIn;				//绑定输入参数的MYSQL_BIND 数组
		MYSQL_BIND	*m_pBindOut;			//绑定输出参数的MYSQL_BIND 数组
		long unsigned int *m_pInLength;		//绑定输入时,将buffer中的字符长度,告知msyql_excute();
		Log4Cplus 		 m_log;
};

#endif




















